package models;

import play.Logger;
import play.db.jpa.GenericModel;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * User: bicho
 * Date: 29/07/12 20:43
 * Email: bichocj@gmail.com
 */
@MappedSuperclass
public class PcModel extends GenericModel {
    //TODO look at for a Play JPA Class that not consider Id like generic

    @Id
    public Long id;

    public Long getId() {
        return id;
    }

    @Override
    public Object _key() {
        return getId();
    }

    public String getDescripcion() {
        String descripcion = "";
        Field[] declaredFields = this.getClass().getDeclaredFields();
        for (Field field : declaredFields) {
            try {
                StringBuilder stringBuilder = new StringBuilder(field.getName());
                descripcion +=
                        stringBuilder.replace(0, 1, stringBuilder.substring(0, 1).toUpperCase()).toString() + ":" + field.get(this) + " ";
            } catch (IllegalAccessException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }
        return descripcion.trim();
    }
}

